feat: Implement Two-Factor Authentication (2FA) support for users#124
feat: Implement Two-Factor Authentication (2FA) support for users#124matiasperrone-exo wants to merge 1 commit intofeature/mfa-phase1from
Conversation
Created PHPUnit test suit "Two Factor Authentication Test Suite" Modified app/libs/Auth/Models/User.php: - public const ValidMFAMethods = ['email_otp']; - 3 new Doctrine-mapped private fields (two_factor_enabled, two_factor_method, two_factor_enforced_at) matching the Phase 1 migration columns - Constructor initializers for the three fields - Getters/setters: isTwoFactorEnabled/setTwoFactorEnabled, getTwoFactorMethod/setTwoFactorMethod, getTwoFactorEnforcedAt/setTwoFactorEnforcedAt - shouldRequire2FA() — config-driven via two_factor.enforced_groups, falls through to the stored flag - enable2FA(string $method) — whitelists via ValidMFAMethods, throws ValidationException otherwise - getAvailableTwoFactorMethods() / isTwoFactorMethodEnable() - Phase II/III stubs returning false: isPhoneNumberVerified, isTOTPConfirmed, isPassKeyEnabled Created config/two_factor.php with enforced_groups referencing IGroupSlugs constants (super-admins, administrators, oauth2-server-admins, openid-server-admins). Created tests/unit/UserTwoFactorTest.php — 11 test methods (25 assertions), all green. Verification: - doctrine:schema:validate: no new diffs on users relating to the 2FA columns — only the pre-existing documented noise (signed/unsigned, index renames). - UserTwoFactorTest: 11/11 passing. - TwoFactorRepositoriesTest (Phase 1): 3/3 still passing.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/openstackid/openapi/pr-124/ This page is automatically updated on each push to this PR. |
Changes
Verification:
Card Description
GOAL
Current state
The User entity (Auth\User) has no 2FA-related properties or methods. Role checking exists via isSuperAdmin() and isAdmin() but there is no mechanism to determine whether a user requires two-factor authentication.
Target state
The User entity exposes the three new database fields as Doctrine-mapped properties and provides the business logic methods needed by the controller and services:
shouldRequire2FA(), enable2FA(), getAvailableTwoFactorMethods(), isTwoFactorMethodEnable(), getTwoFactorMethod(), and the ValidMFAMethods constant.
TASKS
isTOTPConfirmed(), isPassKeyEnabled() return false.
ACCEPTANCE CRITERIA
DEVELOPMENT NOTES
Key files:
Gotchas:
config('two_factor.enforced_groups'), not hardcode group slugs.
Out of scope: Database migration (Ticket 1), controller integration, service layer.